﻿Public Class VietNhatKi 
    Private noidung As String
    Private Sub VietNhatKi_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        If (frmHome.flagEdit) Then
            'Dim nhk As NhatKiDTO
            'nhk.Ngay = frmHome.dnLich.Selection.Item(0).ToShortDateString()
            retNoiDung.Text = frmHome.lbNoiDung.Text
            noidung = retNoiDung.Text
        End If
    End Sub

    Private Sub VietNhatKi_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        If (retNoiDung.Text <> noidung) Then
            If (MessageBox.Show("Nội Dung Đã Thay Đổi, bạn có muốn đóng?", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) = Windows.Forms.DialogResult.No) Then
                e.Cancel = True
            End If
        Else
            retNoiDung.Text = ""
            frmHome.Show()
        End If
    End Sub

    Private Sub bntThem_Click(sender As System.Object, e As System.EventArgs) Handles bntThem.Click
        If (frmHome.flagEdit) Then
            UpdateNK()
        Else
            ThemNK()
        End If
    End Sub

    Private Sub bntLuuVaDong_Click(sender As System.Object, e As System.EventArgs) Handles bntLuuVaDong.Click
        If (frmHome.flagEdit) Then
            UpdateNK()
            Close()
        Else
            ThemNK()
            Close()
        End If
    End Sub

    Sub UpdateNK()
        Dim nhk As New NhatKiDTO() With {.Ngay = frmHome.dnLich.Selection.Item(0).ToShortDateString(), .NoiDung = retNoiDung.Text}
        NhatKiBUS.UpdateNK(nhk)
    End Sub

    Sub ThemNK()
        Dim nhk As New NhatKiDTO() With {.Ngay = Date.Today, .NoiDung = retNoiDung.Text}
        If (NhatKiBUS.Check(nhk)) Then
            NhatKiBUS.ThemNK(nhk)
        Else
            NhatKiBUS.UpdateNK(nhk)
        End If

    End Sub

End Class